package com.bgl.mall.common;

import com.google.common.collect.Sets;
import lombok.Getter;

import java.util.Set;

/**
 * @author BGL
 * @date 2017/5/18
 */
public class Constant {
    public static final String CURRENT_USER = "currentUser";

    public static final String EMAIL = "email";

    public static final String USERNAME = "username";

    public static final String TOKEN_PREFIX = "token_";

    /**
     * TOKEN前缀
     */
    public static final String REDIS_PREFIX_LOGIN = "login_token_%s";
    /**
     * 过期时间2小时
     */
    public static final Integer REDIS_EXPIRE_TWO = 7200;
    /**
     * 过期时间15分
     */
    public static final Integer REDIS_EXPIRE_EMAIL = 900;
    /**
     * 过期时间5分钟
     */
    public static final Integer REDIS_EXPIRE_KAPTCHA = 300;
    /**
     * 暂无过期时间
     */
    public static final Integer REDIS_EXPIRE_NULL = -1;

    public interface Role{
        int ROLE_CUSTOMER = 0;//普通用户
        int ROLE_ADMIN = 1;//管理员用户
    }

    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc", "price_asc");
    }

    public interface RedisCache{
        int REDIS_SESSION_EXTIME = 60 * 30;
    }

    @Getter
    public enum  ProductStatusEnum{
        ON_SALE(1, "在线");

        private int code;

        private String value;

        ProductStatusEnum(int code, String value){
            this.code = code;
            this.value = value;
        }
    }

    public interface Cart{
        int CHECKED = 1;//表示选中状态
        int UN_CHECKED = 0;//表示未选中状态

        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_FAIL";
    }

    @Getter
    public enum OrderStatusEnum{
        CANCELED(0, "已取消"),
        NO_PAY(10, "未支付"),
        PAID(20, "已付款"),
        SHIPPED(40, "已发货"),
        ORDER_SUCCESS(50, "订单完成"),
        ORDER_CLOSE(60, "订单关闭");

        private final int code;
        private final String value;

        OrderStatusEnum(int code, String value){
            this.code = code;
            this.value = value;
        }

        public static String getDesc(int code){
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (code == orderStatusEnum.getCode()) {
                    return orderStatusEnum.getValue();
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }

    public interface aliCallback{
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    @Getter
    public enum PayPlatformEnum{
        ALIPAY(1, "支付宝");

        private final int code;
        private final String value;

        PayPlatformEnum(int code, String value){
            this.code = code;
            this.value = value;
        }
    }

    @Getter
    public enum PaymentTypeEnum{
        PAY_ONLINE(1, "在线支付");

        private final int code;
        private final String value;

        PaymentTypeEnum(int code, String value){
            this.code = code;
            this.value = value;
        }

        public static String getDesc(int code){
            for (PaymentTypeEnum paymentTypeEnum : values()) {
                if (code == paymentTypeEnum.getCode()) {
                    return paymentTypeEnum.getValue();
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
}
